package com.woniuxy.credit_loans.staff_dong.controller;


import com.woniuxy.credit_loans.staff_dong.dto.PerDto;
import com.woniuxy.credit_loans.staff_dong.service.PermissionService;
import com.woniuxy.credit_loans.staff_dong.vo.TreeNode;
import com.woniuxy.credit_loans.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permissions")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @GetMapping("{roleId}")
    public Result selPer(@PathVariable Integer roleId){
        List<TreeNode> treeNodes = permissionService.selectAllPer(0);
        List<Integer> integers = permissionService.selectPerByRoleId(roleId);
        return Result.ok().data("permissionList",treeNodes).data("defaultChecked",integers);
    }

    @PostMapping("")
    public Result changePer(@RequestBody PerDto perDto){
        int i = permissionService.insertPer(perDto);
        return Result.ok();
    }
}
